
package instrumentation;

import java.io.Serializable;

public class DataDef implements Serializable {

	private static final long serialVersionUID = 6331611025925067694L;

	private final int id;
	private static int idGenerator = 1;

	private final Data data;
	private final boolean DataValue;
	private  boolean ValueValue=false; //a[i]=42

	/** The value of the assignment (if a constant or a single variable) */
	private final Value value;
	private  Value value2=null;

	public DataDef( Data data, Value value) {
		id = idGenerator++;

		this.data = data;
		this.value = value;
		DataValue=true;
	}
	public DataDef( Value value, Data data ) {
		id = idGenerator++;

		this.data = data;
		this.value = value;
		DataValue=false;
	}
	public DataDef( Value value, Value value2 ) { //if (a[i]=45)
		id = idGenerator++;

		this.data = null;;
		this.value = value;
		this.value2 = value2;
		DataValue=false;
		ValueValue=true;

	}

	public int getId() {
		return id;
	}

	public Value getData() {
		return data==null? this.value:this.data;
	}

	public boolean isField() {
		return data.isField();
	}
	public Value getValue() {
		return value2==null?this.value:this.value2;
	}

	@Override
	public String toString() {
		String ret="";	
		if(this.DataValue)
		 ret=this.data.toString()+" "+ (this.value==null?"":this.value.toString());

		if(!this.DataValue&&!this.ValueValue)
			ret=(this.value==null?"":this.value.toString())+" "+this.data.toString();
		if(this.ValueValue)
			ret=(this.value==null?"":this.value.toString())+" "+this.value2.toString();

		return ret;
	}
}
